import 'package:flutter/material.dart';
import 'package:test1/bean/ProductInfo.dart';
import 'package:test1/pages/test/Test_Shopping_Car_List_Item_Page.dart';

class Test_Shopping_Car_List_Page extends StatefulWidget {
  List<ProductInfo> list;

  Test_Shopping_Car_List_Page(this.list);

  @override
  State<StatefulWidget> createState() {
    return Test_Shopping_Car_List_State();
  }
}

class Test_Shopping_Car_List_State extends State<Test_Shopping_Car_List_Page> {

  Set<ProductInfo>set = new Set();

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: widget.list.map(
              (ProductInfo info) {
            return Test_Shopping_Car_List_Item_Page(
                info,
                set.contains(info),
                    (productInfo, inCart) {
                  setState(
                          () {
                        if (inCart) {
                          set.add(productInfo);
                        } else {
                          set.remove(productInfo);
                        }
                      }
                  );
                }
            );
          }
      ).toList(),
    );
  }
}